<template>
  <div>
    <!-- <div class="toptitle">角色列表</div> -->
    <el-row id="order_total" style="display:flex">
      <!-- <el-col :span="5"> -->
      <div class="order_content" @click="clickone()">
        <div class="order_total_title">总数</div>
        <div class="order_total_info">
          <span class="order_data">{{ totalData.total }}</span>
        </div>
      </div>
      <!-- </el-col> -->
      <!-- <el-col :span="4"> -->
      <div class="order_content" @click="clicktwo()">
        <div class="order_total_title">强绑定数</div>
        <div class="order_total_info">
          <span class="order_data">{{ totalData.strongBindMemberSum }}</span>
        </div>
      </div>
      <!-- </el-col> -->
      <!-- <el-col :span="6"> -->
      <div class="order_content" @click="clickthree()">
        <div class="order_total_title">弱绑定数</div>
        <div class="order_total_info">
          <span class="order_data">{{ totalData.weakMemberSum }}</span>
        </div>
      </div>
      <!-- </el-col> -->
      <!-- <el-col :span="2"> -->
      <div class="order_content" @click="clickfour()">
        <div class="order_total_title">已流失会员总数</div>
        <div class="order_total_info">
          <span class="order_data">{{ totalData.lostMemberSum }}</span>
        </div>
      </div>
      <!-- </el-col> -->
      <!-- <el-col :span="8"> -->
      <div class="order_content">
        <div class="order_total_title">今日新增会员数</div>
        <div class="order_total_info">
          <span class="order_data">{{ MemberNum }}</span>
        </div>
      </div>
      <!-- </el-col> -->
    </el-row>
    <el-form :inline="true" :model="formInline" class="demo-form-inline" @keyup.enter.native="search()">
      <!-- <el-row :span="24">
              <el-col :span="8"> -->
      <el-form-item label="会员编号">
        <br />
        <br />
        <el-input v-model="formInline.memberSeq" placeholder style="margin-left:-70px;width:200px" clearable></el-input>
      </el-form-item>
      <!-- </el-col> -->
      <!-- <el-col :span="8"> -->
      <el-form-item label="会员昵称" style="margin-left:15px">
        <br />
        <br />
        <el-input v-model="formInline.nickName" placeholder style="margin-left:-70px;width:200px" clearable></el-input>
      </el-form-item>
      <!-- </el-col> -->
      <!-- <el-col :span="8"> -->

      <!-- </el-col> -->
      <!-- <el-col :span="8"> -->
      <el-form-item label="会员手机号">
        <br />
        <br />
        <el-input v-model="formInline.phone" placeholder style="margin-left:-70px;width:200px" clearable></el-input>
      </el-form-item>
      <!-- </el-col> -->
      <!-- <el-col :span="8"> -->

      <!-- </el-col> -->
      <!-- <el-col :span="8"> -->
      <el-form-item v-if="userInfo.userType == '1'" label="大区名称" style="margin-left:15px">
        <br />
        <br />
        <el-input v-model="formInline.orgSeqZQName" placeholder style="margin-left:-70px;width:200px"
          clearable></el-input>
      </el-form-item>
      <!-- </el-col> -->

      <!-- <el-col :span="8"> -->
      <el-form-item v-if="userInfo.userType != '3'" label="营销区域名称" style="margin-left:15px">
        <br />
        <br />
        <el-input v-model="formInline.orgSeqJDName" placeholder style="margin-left:-70px;width:200px"
          clearable></el-input>
      </el-form-item>
      <!-- </el-col> -->
      <!-- <el-col :span="8"> -->
      <el-form-item label="店铺授权编码">
        <br />
        <br />
        <el-input v-model="formInline.authCode" placeholder style="margin-left:-90px;width:200px" clearable></el-input>
      </el-form-item>
      <!-- </el-col> -->
      <!-- <el-col :span="8"> -->
      <el-form-item label="店铺名称" style="margin-left:40px">
        <br />
        <br />
        <el-input v-model="formInline.mdorgSeqName" placeholder style="margin-left:-100px;width:200px"
          clearable></el-input>
      </el-form-item>
      <el-form-item label="会员绑定关系">
        <br />
        <br />
        <el-select v-model="formInline.type" placeholder="全部" clearable style="margin-left:-80px;width:200px">
          <el-option label="全部" value></el-option>
          <!-- <el-option label="总数" value="1"></el-option> -->
          <el-option label="强绑定" value="2"></el-option>
          <el-option label="弱绑定 " value="3"></el-option>
          <el-option label="已流失" value="4"></el-option>
          <el-option label="未绑定 " value="5"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="等级" style="margin-left:20px">
        <br />
        <br />
        <el-select v-model="formInline.gradelevelId" placeholder="全部" clearable style="margin-left:-50px;width:200px">
          <el-option v-for="(send, i) in options" :key="i" :value="send.uuid" :label="send.gradelevelName"></el-option>
        </el-select>
      </el-form-item>
      <!-- </el-col> -->
      <!-- <el-col :span="8"> -->
      <el-form-item label="注册来源" style="margin-left:10px">
        <br />
        <br />
        <el-select v-model="formInline.memberType" placeholder="全部" clearable style="margin-left:-70px;width:200px">
          <el-option label="全部" value></el-option>
          <el-option label="自主注册" value="1"></el-option>
          <el-option label="商品分享注册" value="2"></el-option>
          <el-option label="活动分享注册" value="3"></el-option>
          <el-option label="店铺分享注册" value="4"></el-option>
          <el-option label="分享有礼" value="5"></el-option>
          <!-- <el-option label="注册有礼" value="6"></el-option> -->
        </el-select>
      </el-form-item>
      <!-- </el-col> -->
      <!-- <el-col :span="8"> -->
      <el-form-item label="是否包含资质信息">
        <br />
        <br />
        <el-select v-model="formInline.isQualification" placeholder="全部" clearable
          style="margin-left:-110px;width:200px">
          <el-option label="全部" value=""></el-option>
          <el-option label="是" value="1"></el-option>
          <el-option label="否" value="0"></el-option>
        </el-select>
      </el-form-item>
      <!-- </el-col> -->
      <!-- <el-col :span="8"> -->
      <el-form-item label="状态" style="margin-left:10px">
        <br />
        <br />
        <el-select v-model="formInline.blockStatus" placeholder="全部" clearable style="margin-left:-50px;width:200px">
          <el-option label="全部" value></el-option>
          <el-option label="停用" value="0"></el-option>
          <el-option label="启用" value="1"></el-option>
        </el-select>
      </el-form-item>
      <!-- </el-col>  -->
      <!-- </el-row> -->
      <!-- <el-row :span="24"> -->
      <!-- <el-form-item>
        <el-button type="primary" @click="kong()" size="mini" icon="el-icon-delete">清空</el-button>
      </el-form-item>-->

      <!-- <el-form-item label="当前组织名称：">
        <el-input v-model="formInline.orgName" placeholder style="width:200px"></el-input>
      </el-form-item> -->
      <el-form-item label="创建时间" style="margin-left:10px">
        <br />
        <br />
        <el-date-picker v-model="formInline.dateRange" style="margin-left:-70px;width:430px" type="daterange"
          align="right" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
          value-format="yyyy-MM-dd"></el-date-picker>
      </el-form-item>
      <!-- <el-form-item>
        <el-button type="primary" @click="add()" size="mini" icon="el-icon-add">选择组织</el-button>
      </el-form-item> -->
      <el-form-item style="margin-left:700px;text-align:right;margin-top:20px">
        <el-button type="primary" @click="kong()" size="mini" icon="el-icon-delete">清空</el-button>
        <!-- </el-form-item>
      <el-form-item> -->
        <el-button type="primary" :disabled="fenyeflagone" @click="search()" size="mini" icon="el-icon-search"
          v-preventReClick>查询</el-button>
        <!-- </el-form-item> -->
        <!-- <el-form-item> -->
        <el-button type="primary" @click="showConfigTableDialog()" size="mini" icon="el-icon-setting"
          :loading="insertLoading">列表配置</el-button>
      </el-form-item>
      <!-- <el-form-item>
        <el-button type="success"    @click="exportExcel()" size="mini" icon="el-icon-s-data">导出</el-button>
      </el-form-item> -->

      <!-- </el-row> -->
    </el-form>
    <div class="table-wrapper">
      <el-table :data="tableData" border style="width: 100%;" height="400px" ref="qtable" v-loading="loading"
        :header-cell-style="{ background: '#ebecf0', color: '#606266' }" @sort-change="handleSort">
        <el-table-column type="index" width="60" label="序号" align="center" :index="indexMethod"></el-table-column>
        <el-table-column v-for="(item, index) in col" :key="`col_${index}`" :prop="dropCol[index].prop"
          :width="dropCol[index].width" :min-width="200" :label="item.label" align="center" :sortable="item.sortable">
          <template slot-scope="scope">
            <div v-if="dropCol[index].prop === 'status'">
              {{ scope.row.blockStatus === 0 ? '停用' : '启用' }}
            </div>
            <div v-if="dropCol[index].prop === 'bdstatus'">
              <span v-if="scope.row.bdstatus === '1'">强绑定</span>
              <span v-if="scope.row.bdstatus === '2'">弱绑定</span>
              <span v-if="scope.row.bdstatus === '3'">已流失</span>
            </div>
            <div v-if="dropCol[index].prop === 'memberType'">
              <span v-if="scope.row.memberType === 1">自主注册</span>
              <span v-if="scope.row.memberType === 2">商品分享注册</span>
              <span v-if="scope.row.memberType === 3">活动分享注册</span>
              <span v-if="scope.row.memberType === 4">店铺分享注册</span>
              <span v-if="scope.row.memberType === 5">分享有礼</span>
              <span v-if="scope.row.memberType === 6">注册有礼</span>
            </div>
            <!-- <div v-if="dropCol[index].prop === 'zhuuid'">
                <span v-if="scope.row.zhuuid!==null">是</span>
                <span v-if="scope.row.zhuuid==null">否</span>
            
              </div> -->
            <div v-if="dropCol[index].prop === 'sex'">
              <span v-if="scope.row.sex === 1">男</span>
              <span v-if="scope.row.sex === 2">女</span>
            </div>
            <div v-if="dropCol[index].prop === 'zhuuid'">
              <span v-if="scope.row.zhuuid == null">否</span>
              <span v-if="scope.row.zhuuid != null">是</span>
            </div>
            <div v-if="
              dropCol[index].prop != 'status' &&
              dropCol[index].prop != 'bdstatus' &&
              dropCol[index].prop != 'memberType' &&
              dropCol[index].prop != 'sex' &&
              dropCol[index].prop != 'zhuuid'
            ">
              {{ scope.row[dropCol[index].prop] }}
            </div>
          </template>
        </el-table-column>
        <!--
          <el-table-column prop="memberSeq" label="会员编码" align="left" width="145"></el-table-column>
        <el-table-column prop="userName" label="会员真实姓名" align="left" width="100"></el-table-column>

          <el-table-column prop="nickName" label="会员昵称" align="left"></el-table-column>
             <el-table-column prop="upOrgZone" label="大区名称" align="left"  width="100"></el-table-column>
                  <el-table-column prop="jdname" label="营销区域名称" align="left"  width="100"></el-table-column>
                    <el-table-column prop="status" label="状态">
        <template slot-scope="scope">{{scope.row.blockStatus===0?'停用':'启用'}}</template>
      </el-table-column>
            <el-table-column prop="bdstatus" label="会员绑定关系" align="left"  width="100">
            
                <template slot-scope="scope">
          <span v-if="scope.row.bdstatus==='1'">强绑定</span>
          <span v-if="scope.row.bdstatus==='2'">弱绑定</span>
            <span v-if="scope.row.bdstatus==='3'">已流失</span>
            -->
        <!-- 
                <el-option label="强绑定" value="2"></el-option>
           <el-option label="弱绑定 " value="3"></el-option>
            <el-option label="已流失" value="4"></el-option>
           <el-option label="未绑定 " value="5"></el-option> -->
        <!--   
        </template>
        
            </el-table-column>
             <el-table-column prop="memberType" label="注册来源" align="left"  width="100">
                <template slot-scope="scope">
          <span v-if="scope.row.memberType===1">自主注册</span>
          <span v-if="scope.row.memberType===2">产品分享注册</span>
            <span v-if="scope.row.memberType===3">活动分享注册</span>
          <span v-if="scope.row.memberType===4">店铺分享注册</span>
              <span v-if="scope.row.memberType===5">分享有礼</span>
          <span v-if="scope.row.memberType===6">注册有礼</span>
           
        </template>
        </el-table-column>
                <el-table-column
          prop="authCode"
          label="店铺授权编码"
          align="left"
          width="145"
        
        ></el-table-column>
        <el-table-column
          prop="mdorgSeqName"
          label="所属门店"
          align="left"
          width="145"
        
        ></el-table-column>
        <el-table-column prop="currentScore" label="会员积分" align="left" width="100"    ></el-table-column>
         <el-table-column prop="remarkName" label="会员备注" align="left" width="80"></el-table-column>
        <el-table-column prop="cellPhoneNo" label="手机号码" align="left"  width="130"></el-table-column>
        -->
        <!-- <el-table-column prop="address" label="地址" align="left"></el-table-column> -->
        <!--
        <el-table-column prop="sex" label="性别" header-align="center" width="50">
          <template slot-scope="scope">
            <span v-if="scope.row.sex===1">男</span>
            <span v-if="scope.row.sex===2">女</span>
          </template>
        </el-table-column>

        <el-table-column prop="gradeLevel" label="会员等级" align="left" width="100"></el-table-column>
           <el-table-column prop="createTime" label="创建时间" align="left" width="150"></el-table-column>
        -->

        <!-- <el-table-column prop="memberTypeone" label="会员类型" align="left"></el-table-column> -->
        <el-table-column label="操作" fixed="right" align="center" width="280">
          <template slot-scope="scope">
            <el-button size="mini" @click="edit(scope.row)" type="text">查看详情</el-button>
            <el-button type="text" v-if="userInfo.userType == '1' && (scope.row.blockStatus == 1 && flagdianone)" size="mini" @click="
              updateStatus(scope.row.memberId, 0, scope.row.cellPhoneNo)
              ">停用</el-button>
            <el-button type="text" v-if="userInfo.userType == '1' && (scope.row.blockStatus == 0 && flagdianone)" @click="
              updateStatus(scope.row.memberId, 1, scope.row.cellPhoneNo)
              " size="mini">启用</el-button>
            <el-button v-if="userInfo.userType == '1'" type="text" size="mini" @click="relatedOrder(scope.row)">关联订单</el-button>
            <el-button type="text" size="mini" @click="relatedCoin(scope.row)">酒币明细</el-button>
            <el-button v-if="userInfo.userType == '1'" type="text" size="mini" @click="giveCoin(scope.row)">赠送酒币</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="block" style="margin-top:10px">
        <el-pagination :disabled="fenyeflag" @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :page-sizes="[10, 20, 30, 50, 100]" :current-page="listQuery.current" :page-size="listQuery.size"
          layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
      </div>
    </div>
    <el-dialog :visible.sync="dialogVisible">
      <el-tree :data="dataorg" highlight-current ref="tree" show-checkbox node-key="orgSeq" :props="defaultProps" lazy
        @node-click="handleNodeClick3" @check-change="handleNodeClick" @check="handleNodeClickone"
        :default-checked-keys="this.checkedarr" default-expand-all check-strictly></el-tree>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="mini">取 消</el-button>
        <el-button type="primary" @click="surefenrole()" size="mini">确 定选择组织</el-button>
      </span>
    </el-dialog>
    <el-dialog :visible.sync="dialogVisibledetail" title="会员详情">
      <el-form ref="form" label-width="120px" :model="form" :disabled="true" style="margin-left: 70px;">
        <!-- <el-tabs type="border-card">
          <el-tab-pane label="会员详细信息"> -->
        <el-form-item label="会员名称：">
          <el-input v-model="memberList.userName" style="width:400px"></el-input>
        </el-form-item>

        <el-form-item label="会员昵称：">
          <el-input v-model="memberList.nickName" style="width:400px"></el-input>
        </el-form-item>

        <!-- <el-form-item label="会员类型：">
              <el-input v-model="memberList.memberType"></el-input>
            </el-form-item> -->

        <el-form-item label="会员等级：">
          <el-input v-model="memberList.gradeLevel" style="width:400px"></el-input>
        </el-form-item>

        <el-form-item label="联系地址：">
          <el-input v-model="memberList.position" style="width:400px"></el-input>
        </el-form-item>
        <!-- </el-tab-pane> -->
        <!-- <el-tab-pane label="会员个人信息"> -->

        <el-form-item label="创建时间：">
          <el-input v-model="memberList.createTime" style="width:400px"></el-input>
        </el-form-item>
        <el-form-item label="会员积分：">
          <el-input v-model="memberList.currentScore" style="width:400px"></el-input>
        </el-form-item>
        <el-form-item label="手机号：">
          <el-input v-model="memberList.cellPhoneNo" style="width:400px"></el-input>
        </el-form-item>
        <el-form-item label="性别：">
          <el-input v-model="memberList.sex" style="width:400px"></el-input>
        </el-form-item>

        <el-form-item label="生日：">
          <el-input v-model="memberList.birthday" style="width:400px"></el-input>
        </el-form-item>

        <el-form-item label="会员头像：">
          <img :src="memberList.headPicUrl" />
        </el-form-item>
        <!-- </el-tab-pane> -->
        <!-- </el-tabs> -->

        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisibledetail = false" size="mini">取 消</el-button>
          <el-button type="primary" @click="dialogVisibledetail = false" size="mini">确 定</el-button>
        </span>
      </el-form>
    </el-dialog>

    <!--列表配置-->
    <el-dialog title="列表配置" :visible.sync="configTableDialogVisible" width="50%" @close="closeConfigTableDialog()">
      <div id="configTableDiv">
        <el-form :inline="true" :model="formInline2" class="demo-form-inline">
          <el-form-item label="选择列表字段：">
            <el-checkbox :indeterminate="formInline2.isIndeterminate" v-model="formInline2.isAll"
              style="margin-top:10px;" @change="isAllFieldChange">全选</el-checkbox>
          </el-form-item>
          <el-divider></el-divider>
          <el-checkbox-group v-model="userMenuShowFields" @change="isSingleFieldChange">
            <el-checkbox v-for="item in userMenuFieldList" :label="item.fieldCode" :key="item.fieldCode"
              style="margin:15px 10px;width:120px;">{{ item.fieldName }}</el-checkbox>
          </el-checkbox-group>
        </el-form>
        <el-row>
          <el-col :span="24" style="text-align: center;margin-top: 30px">
            <el-button type="info" @click="closeConfigTableDialog()" size="mini">取 消</el-button>
            <el-button type="primary" @click="insertUserFieldRelation()" size="mini">确 认</el-button>
          </el-col>
        </el-row>
      </div>
    </el-dialog>

    <!-- 赠送云币 -->
    <GiveCoinDialog :show.sync="showGiveCoinDialog" :memberId="curMemberId" :type="0" @refresh="_memberManage" />
  </div>
</template>

<script>
import Sortable from 'sortablejs';
import {
  queryUserMenuFieldByParam,
  insertUserFieldRelation,
} from '@/api/tradeOrderSearch';
import { getmemberrule, getMemberExcel } from '@/api/membergrade';
import {
  memberManage,
  updatememberinfo,
  delmemberinfo,
  queryStoreOrgseq,
  getGraCount,
  queryMemberDetail,
  getMemberNum,
  editClerk,
} from '@/api/memberinfo';
import qs from 'qs';
import GiveCoinDialog from './components/GiveCoinDialog.vue';
export default {
  components: {
    GiveCoinDialog
  },
  data() {
    return {
      loading: true,
      options: [],
      checkedarr: [],
      flagmendian: false,
      fenyeflag: false,
      fenyeflagone: false,
      dataorg: [],
      defaultProps: {
        children: 'children',
        label: 'orgName',
        isLeaf: false,
      },
      listQuery: {
        current: 1,
        size: 10,
      },
      MemberNum: '',
      memberList: {},
      detailform: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: '',
      },
      dialogVisibledetail: false,
      total: 0,
      formInline: {
        sortList: [],
        nickName: '',
        memberSeq: '',
        memberType: '',
        isQualification: '',
        type: '',
        orgName: '',

        name: '',
        phone: '',
        orgSeqJDName: '',
        authCode: '',
        mdorgSeqName: '',
        orgSeqZQName: '',
        gradelevelId: '',
        blockStatus: '',
        dateRange: [],
      },
      totalData: {
        total: 0,
        strongBindMemberSum: 0,
        weakMemberSum: 0,
      },
      data5: [],
      data3: [],
      data4: [],
      resone: [],
      objone: {},
      tableData: [],
      multipleSelection: [],
      radio: '',
      rolefenid: '',
      selected: {},
      num: 0,
      onpresscTime: 0, //  阻止短时间内连续点击
      form: {
        nickName: '',
        sex: '',
        memberType: '',
        membercardId: '',
        cellPhoneNo: '',
      },
      type: '1',
      orgList: {},
      roleid: '',
      flagdianone: false,
      dialogVisibleone: false,
      dialogVisibletwo: false,
      dialogVisible: false,
      insertLoading: false,
      configTableDialogVisible: false, //列表配置弹窗状态
      formInline2: {
        isIndeterminate: false, //是否半选中
        isAll: true, //是否全部显示,
        menuCode: 'memberInfo',
      },
      userMenuFieldList: [], //全部列名列表
      userMenuAllFields: [], //全部的列名
      userMenuShowFields: [], //显示的列名
      userOldMenuShowFields: [], //原显示的列名
      allCol: [],
      col: [],
      dropCol: [],
      ruledata: [],

      // 赠送云币相关
      showGiveCoinDialog: false,
      curMemberId: '',

      userInfo: {},
    };
  },
  mounted() {
    var nowDay = this.getNowDay();
    var beginDay = this.getMonthOneDay();
    this.formInline.dateRange = [beginDay, nowDay];

    this.num = 0;
    this.queryUserMenuFieldByParam(); //加载列表配置字段
    this.checkedarr = [];
    this.logininfo = localStorage.getItem('logininfo');
    this.userInfo = JSON.parse(this.logininfo);

    this.orgList = JSON.parse(this.logininfo).orgList;
    this.formInline.orgName = this.orgList[0].orgName;
    console.log(this.orgList, '000333');
    this.orgList.forEach((item, i) => {
      if (this.orgList[i].userType == 1) {
        this.flagdianone = true;
      }

      document.body.ondrop = function (event) {
        event.preventDefault();
        event.stopPropagation();
      };
      // this.rowDrop()
      this.columnDrop();
    });
    this.resone = this.orgList[0].orgSeq;
    this.checkedarr.push(this.resone);
    console.log(this.resone, '000388');
    this._memberManage();
    this._getGraCount();
    this._getmemberinfo();
    this._getMemberNum();
  },

  methods: {
    //拖拽列表
    columnDrop() {
      const wrapperTr = document.querySelector('.el-table__header-wrapper tr');
      this.sortable = Sortable.create(wrapperTr, {
        animation: 180,
        delay: 0,
        onEnd: (evt) => {
          const oldItem = this.dropCol[evt.oldIndex - 1];
          this.dropCol.splice(evt.oldIndex - 1, 1);
          this.dropCol.splice(evt.newIndex - 1, 0, oldItem);
        },
      });
    },
    getNowDay() {
      var date = new Date();
      var seperator1 = '-';
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var strDate = date.getDate();
      if (month >= 1 && month <= 9) {
        month = '0' + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = '0' + strDate;
      }
      var currentdate = year + seperator1 + month + seperator1 + strDate;
      return currentdate;
    },
    // 获取当前时间的前30天的日期
    getMonthOneDay() {
      var date = new Date();
      // 计算30天前的日期
      date.setDate(date.getDate() - 30);

      var seperator1 = '-';
      var year = date.getFullYear();
      var month = date.getMonth() + 1; // 月份从0开始，需+1
      var day = date.getDate();

      // 补零逻辑
      month = month.toString().padStart(2, '0'); // 始终补零到两位
      day = day.toString().padStart(2, '0');     // 日期补零

      var targetDate = year + seperator1 + month + seperator1 + day;
      return targetDate;
    },
    exportExcel() {
      let data = {
        size: this.listQuery.size,
        current: 1,
        condition: {
          nickName: this.formInline.nickName,
          memberSeq: this.formInline.memberSeq,
          memberType: this.formInline.memberType,
          isQualification: this.formInline.isQualification,
          type: this.formInline.type,
          type: this.type,
          orgSeq: this.resone,
          phone: this.formInline.phone,
          orgSeqJDName: this.formInline.orgSeqJDName,
          authCode: this.formInline.authCode,
          mdorgSeqName: this.formInline.mdorgSeqName,
          orgSeqZQName: this.formInline.orgSeqZQName,
          gradelevelId: this.formInline.gradelevelId,
          createBeginTime:
            this.formInline.dateRange !== undefined &&
              this.formInline.dateRange.length > 0
              ? this.formInline.dateRange[0]
              : '',
          createEndTime:
            this.formInline.dateRange !== undefined &&
              this.formInline.dateRange.length > 1
              ? this.formInline.dateRange[1]
              : '',
        },
        ascs: [],
        descs: [],
      };
      getMemberExcel(data)
        .then((res) => {
          const link = document.createElement('a');
          let blob = new Blob([res], { type: 'application/vnd.ms-excel' });
          link.style.display = 'none';
          //设置连接
          link.href = URL.createObjectURL(blob);
          link.download = '会员档案列表';
          document.body.appendChild(link);
          //模拟点击事件
          link.click();
        })
        .catch((err) => {
          console.log(err);
        });
    },
    updateStatus(memberId, blockStatus, cellPhoneNo) {
      let data = {
        blockStatus: blockStatus,

        memberId: memberId,
        phone: cellPhoneNo,
      };
      console.log('ioippp');
      this.$confirm('确认此操作吗？').then((_) => {
        editClerk(data).then((res) => {
          if (res.code == 1) {
            this.$message({
              showClose: true,
              message: '操作成功',
              type: 'success',
            });

            this._memberManage();
          } else {
            this.$message({
              showClose: true,
              message: '操作失败',
              type: 'error',
            });
          }
        });
      });
    },
    kong() {
      this.formInline.sortList = [];
      this.formInline.nickName = '';
      this.formInline.memberSeq = '';
      this.formInline.cellPhoneNo = '';
      this.formInline.phone = '';
      this.formInline.gradelevelId = '';
      this.formInline.orgName = '';
      this.formInline.memberType = '';
      (this.formInline.isQualification = ''), (this.formInline.type = '');
      (this.formInline.orgSeqJDName = ''),
        (this.formInline.authCode = ''),
        (this.formInline.mdorgSeqName = ''),
        (this.formInline.orgSeqZQName = ''),
        (this.formInline.blockStatus = ''),
        (this.formInline.dateRange = []);
    },
    handleNodeClickone(data, checked, node) {
      console.log(data, checked, node, 'ioioio');
      this.formInline.orgName = data.orgName;
    },
    handleNodeClick(data, checked, node) {
      console.log(data, checked, node, '111');
      if (checked === true) {
        this.checkedId = data.orgSeq;
        this.$refs.tree.setCheckedKeys([data.orgSeq]);
      } else {
        if (this.checkedId == data.orgSeq) {
          this.$refs.tree.setCheckedKeys([data.orgSeq]);
        }
      }
      this.resone = this.$refs.tree.getCheckedKeys();
    },
    // },
    surefenrole() {
      this._memberManage();
      this.resone = this.resone[0];
      this._getGraCount();
      console.log(this.resone, 'io88');
      this.dialogVisible = !this.dialogVisible;
    },
    search() {
      // if (
      //   this.formInline.dateRange == undefined ||
      //   this.formInline.dateRange == null ||
      //   this.formInline.dateRange.length <= 0
      // ) {
      //   this.$message.error('请选择创建时间');
      //   return;
      // }
      this.fenyeflagone = true;
      //       this.num+=1
      //       console.log(this.num,"klk")
      //       if(this.num>1){
      //     setTimeout(()=>{

      //            this.$notify({
      //           title: '警告',
      //           message: '请勿频繁点击',
      //           type: 'warning'
      //         });

      //           }
      // ,2000)
      //       }

      this.loading = true;
      let data = {
        size: this.listQuery.size,
        current: 1,
        condition: {
          sortList: this.formInline.sortList,
          nickName: this.formInline.nickName,
          memberSeq: this.formInline.memberSeq,
          memberType: this.formInline.memberType,
          isQualification: this.formInline.isQualification,
          type: this.formInline.type,
          // type: this.type,
          orgSeq: this.resone,
          phone: this.formInline.phone,
          gradelevelId: this.formInline.gradelevelId,
          orgSeqJDName: this.formInline.orgSeqJDName,
          authCode: this.formInline.authCode,
          mdorgSeqName: this.formInline.mdorgSeqName,
          orgSeqZQName: this.formInline.orgSeqZQName,
          blockStatus: this.formInline.blockStatus,
          createBeginTime:
            this.formInline.dateRange !== undefined &&
              this.formInline.dateRange.length > 0
              ? this.formInline.dateRange[0]
              : '',
          createEndTime:
            this.formInline.dateRange !== undefined &&
              this.formInline.dateRange.length > 1
              ? this.formInline.dateRange[1]
              : '',
        },
        ascs: [],
        descs: [],
      };
      memberManage(data).then((res) => {
        if (res.code == 1) {
          this.fenyeflagone = false;
          this.loading = false;
          this.tableData = res.records;
          this.total = res.total;
        } else {
          this.loading = true;
        }
      });
    },

    handledelete(v) {
      let data = {
        memberId: v.memberId,
      };
      this.$confirm('确认删除吗？').then((_) => {
        delmemberinfo(qs.stringify(data)).then((res) => {
          this.$message({
            showClose: true,
            message: '删除成功',
            type: 'success',
          });
          this._memberManage();
        });
      });
    },
    add() {
      this.logininfo = localStorage.getItem('logininfo');
      //   console.log(this.logininfo.userId, "000");
      this.orgList = JSON.parse(this.logininfo).orgList;
      console.log(this.orgList, '000');
      //   console.log(this.logininfo.userId, "000");
      //   this.logininfo.orgList.forEach((item, i) => {
      //     this.dataorg.push(item);
      //   });
      //   console.log(this.dataorg, "000");

      this.dialogVisible = !this.dialogVisible;
      this._queryStoreOrgseq();
    },
    clickone() {
      this.type = '1';
      this.flagmendian = false;
      this._memberManage();
    },
    clicktwo() {
      this.type = '2';
      this.flagmendian = true;
      this._memberManage();
    },
    clickthree() {
      this.type = '3';
      this.flagmendian = false;
      this._memberManage();
    },
    clickfour() {
      this.type = '4';
      this.flagmendian = false;
      this._memberManage();
    },
    _memberManage() {
      let data = {
        size: this.listQuery.size,
        current: this.listQuery.current,
        ascs: [],
        descs: [],
        condition: {
          sortList: this.formInline.sortList,
          nickName: this.formInline.nickName,
          memberSeq: this.formInline.memberSeq,
          memberType: this.formInline.memberType,
          type: this.formInline.type,
          // type: this.type,
          orgSeq: this.resone,
          phone: this.formInline.phone,
          gradelevelId: this.formInline.gradelevelId,
          orgSeqJDName: this.formInline.orgSeqJDName,
          authCode: this.formInline.authCode,
          mdorgSeqName: this.formInline.mdorgSeqName,
          orgSeqZQName: this.formInline.orgSeqZQName,
          blockStatus: this.formInline.blockStatus,
          createBeginTime:
            this.formInline.dateRange !== undefined &&
              this.formInline.dateRange.length > 0
              ? this.formInline.dateRange[0]
              : '',
          createEndTime:
            this.formInline.dateRange !== undefined &&
              this.formInline.dateRange.length > 1
              ? this.formInline.dateRange[1]
              : '',
        },
      };
      memberManage(data).then((res) => {
        if (res.code == 1) {
          this.loading = false;
          this.tableData = res.records;
          this.total = res.total;
          this.fenyeflag = false;
          //         this.dom = this.$refs.qtable.bodyWrapper
          //  console.log(this.dom);
          //  this.dom.addEventListener('scroll', () => {this.$nextTick(() => {　　　　//滚动高度
          //       let scrollTop = this.dom.scrollTop
          //       if(scrollTop >30){
          //         $(".is-center").css('top','-7px')
          //          $(".is-hidden").css('top','0px')
          //          $(".is-leaf").css('top','0px')
          //       }else{
          //         $(".is-center").css('top','0px')
          //       }

          //     });
          //  });
        } else {
          this.loading = true;
        }
      });
    },
    _queryStoreOrgseq() {
      let data = {
        orgSeq: this.orgList[0].orgSeq,
      };
      queryStoreOrgseq(data).then((res) => {
        this.dataorg = res.records;
        console.log(data);
      });
    },
    _getGraCount() {
      console.log(this.resone, 'io555');
      let data = {
        orgSeq: this.resone,
      };
      getGraCount(data).then((res) => {
        console.log(data);
        this.totalData = res.result;
      });
    },
    edit(v) {
      this.$router.push({
        name: 'memberInfodetail',
        params: {
          v: v,
        },
      });
      //   console.log(v, "po");
      //   this.dialogVisibledetail = !this.dialogVisibledetail;
      //   let data = {
      //     memberId: v.memberId
      //   };
      //   queryMemberDetail(data).then(res => {
      //     console.log(data);
      //     this.memberList = res.result;
      //     res.records[0].sex=1?this.memberList.sex = "男":this.memberList.sex = "女";
      //   });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.listQuery.size = val;
      this._memberManage();
    },
    handleCurrentChange(val) {
      this.loading = true;
      this.fenyeflag = true;
      console.log(`当前页: ${val}`);
      this.listQuery.current = val;
      this._memberManage();
    },
    indexMethod(index) {
      let curpage = this.listQuery.current; //单前页码，具体看组件取值
      let limitpage = this.listQuery.size; //每页条数，具体是组件取值
      return index + 1 + (curpage - 1) * limitpage;
    },
    _getmemberinfo() {
      let data = {
        size: 99,
        current: 1,
        condition: {},
        ascs: [],
        descs: [],
      };
      getmemberrule(data).then((res) => {
        this.options = res.records;
      });
    },

    _getMemberNum() {
      getMemberNum().then((res) => {
        // this.options = res.records;
        this.MemberNum = res.result;
      });
    },
    handleNodeClick3(data) {
      console.log(data.children, 'children');
      console.log(data.level, 'level');
      //判断有children并且children为空
      if (
        data.level > 0 &&
        data.level < 4
        // && data.level.length === 0
      ) {
        let data2 = {
          orgSeq: data.orgSeq,
        };
        queryStoreOrgseq(data2)
          .then((response) => {
            data.children = response.records[0].children;
            //因为我们只有二级，所以我已经让第二级不用去请求，直接去掉那个三角icon
            data.children.forEach(function (value, i) {
              value.level < 3 ? true : false;
            });
            loadingInstance.close();
          })
          .catch(() => {
            this.loading = false;
          });
        // this.treeData[data.$treeNodeId - 1].children = treeData1
        // data.children = this.treeData1[0].children
      }
    },
    handleNodeClick2(data) {
      console.log('node', data);
    },
    // 异步树叶子节点懒加载逻辑
    loadNode(node, resolve) {
      console.log(node);
      console.log(resolve);
      // 一级节点处理
      if (node.level === 0) {
        this.requestTree(resolve);
      }
      // 其余节点处理
      if (node.level >= 1) {
        // 注意！把resolve传到你自己的异步中去
        this.getIndex(node, resolve);
      }
    },
    // 异步加载叶子节点数据函数
    getIndex(node, resolve) {
      var param = {
        code: '002',
        provinceId: node.data.regionCode,
      };
      var url = '/base/inter';
      this.$ajax
        .post(url, param)
        .then((out) => {
          console.log(out.data.data);
          // 此处需要后台传过来一个值来判断每个节点有无子节点,实际项目中必须加上（如isRealLeaf），不传都默认为叶子节点
          //  out.data.data.forEach(value => {
          //   if (value.isRealLeaf === 'Y') {
          //     value.leaf = true//不为叶子节点
          //   } else {
          //     value.leaf = false//为叶子节点
          //   }
          // })
          let data = out.data.data;
          resolve(data);
        })
        .catch((error) => { });
    },
    // 首次加载一级节点数据函数
    requestTree(resolve) {
      var param = {
        code: '001',
      };
      var url = '/base/inter';
      this.$ajax
        .post(url, param)
        .then((out) => {
          console.log(out.data.data);
          // 此处需要后台传过来一个值来判断每个节点有无子节点,实际项目中必须加上（如isRealLeaf），不传都默认为叶子节点
          //  out.data.data.forEach(value => {
          //   if (value.isRealLeaf === 'Y') {
          //     value.leaf = true//不为叶子节点
          //   } else {
          //     value.leaf = false//为叶子节点
          //   }
          // })
          let data = out.data.data;
          resolve(data);
        })
        .catch((error) => { });
    },
    //显示配置弹窗
    showConfigTableDialog() {
      this.userMenuShowFields = this.userOldMenuShowFields;
      let checkedCount = this.userMenuShowFields.length;
      this.formInline2.isAll = checkedCount === this.userMenuAllFields.length;
      this.formInline2.isIndeterminate =
        checkedCount > 0 && checkedCount < this.userMenuAllFields.length;
      this.configTableDialogVisible = true;
    },
    //关闭配置弹窗
    closeConfigTableDialog() {
      this.configTableDialogVisible = false;
      let data = {
        menuCode: this.formInline2.menuCode,
      };
    },
    queryUserMenuFieldByParam() {
      let data = {
        menuCode: this.formInline2.menuCode,
      };
      this.userMenuAllFields = []; //全部的列名
      this.userMenuShowFields = []; //显示的列名
      queryUserMenuFieldByParam(data).then((res) => {
        this.userMenuFieldList = res.records;
        this.userMenuFieldList.forEach((item, index) => {
          this.userMenuAllFields.push(item.fieldCode);
          if (item.isShow == 1) {
            this.userMenuShowFields.push(item.fieldCode);
          }
        });
        if (
          this.userMenuShowFields.length == 0 ||
          this.userMenuShowFields.length == this.userMenuAllFields.length
        ) {
          this.userMenuShowFields = this.userMenuAllFields;
          this.formInline2.isAll = true;
        } else {
          this.formInline2.isAll = false;
          this.formInline2.isIndeterminate = true;
        }
        this.insertUserFieldRelation(1);
      });
    },
    getNewCol() {
      let data = {
        menuCode: this.formInline2.menuCode,
      };
      this.col = [];
      this.dropCol = [];
      queryUserMenuFieldByParam(data).then((res) => {
        this.userMenuFieldList = res.records;
        this.userMenuFieldList.forEach((item, index) => {
          if (item.isShow == 1) {
            this.col.push({ label: item.fieldName, prop: item.fieldCode });
            this.dropCol.push({ label: item.fieldName, prop: item.fieldCode });
          }
        });
        if (this.col.length == 0) {
          this.col = this.allCol;
          this.dropCol = this.allCol;
          this.formInline2.isAll = true;
        }
        this.col.forEach((item, index) => {
          if (item.prop == 'currentScore') {
            this.$set(item, 'sortable', 'currentScore');
          }
        });
      });
    },
    //保存显示字段
    insertUserFieldRelation(isInit) {
      if (
        this.userMenuShowFields == null ||
        this.userMenuShowFields.length == 0
      ) {
        this.$message({
          showClose: true,
          message: '列表字段不可为空',
          type: 'info',
        });
        return;
      }
      let data = {
        menuCode: this.formInline2.menuCode,
        fieldList: this.userMenuShowFields,
      };
      if (isInit == 1) {
        insertUserFieldRelation(data).then((res) => {
          if (res.code == 1) {
            this.userOldMenuShowFields = this.userMenuShowFields;
            this.closeConfigTableDialog();
            this.getNewCol();
          }
        });
        return;
      }
      this.insertLoading = true;
      insertUserFieldRelation(data).then((res) => {
        this.insertLoading = false;
        if (res.code == 1) {
          this.$message({
            showClose: true,
            message: res.message,
            type: 'success',
          });
          this.userOldMenuShowFields = this.userMenuShowFields;
          this.closeConfigTableDialog();
          this.getNewCol();
        } else {
          this.$message({
            showClose: true,
            message: res.message,
            type: 'error',
          });
        }
      });
    },
    //是否全选字段
    isAllFieldChange(val) {
      this.userMenuShowFields = val ? this.userMenuAllFields : [];
      this.formInline2.isIndeterminate = false;
    },
    //是否选中单个字段
    isSingleFieldChange(val) {
      let checkedCount = this.userMenuShowFields.length;
      this.formInline2.isAll = checkedCount === this.userMenuAllFields.length;
      this.formInline2.isIndeterminate =
        checkedCount > 0 && checkedCount < this.userMenuAllFields.length;
    },
    //获取字段勾选状态
    getUserMenuFieldStatus(fieldCode) {
      if (this.userMenuShowFields != null) {
        for (let i = 0; i < this.userMenuShowFields.length; i++) {
          if (this.userMenuShowFields[i] == fieldCode) {
            return true;
          }
        }
        return false;
      }
    },
    //是否显示字段
    isShow(fieldCode) {
      if (this.formInline2.isAll || this.getUserMenuFieldStatus(fieldCode)) {
        return true;
      } else {
        return false;
      }
    },
    handleSort(val) {
      let sortModel = '';
      if (val.order === 'ascending') {
        sortModel = 'ASC';
        if (val.prop == 'currentScore') {
          this.formInline.sortList = [
            { sort: 'asc', sortField: 'currentScore' },
          ];
          this.search();
        }
      } else if (val.order === 'descending') {
        sortModel = 'DESC';
        if (val.prop == 'currentScore') {
          this.formInline.sortList = [
            { sort: 'desc', sortField: 'currentScore' },
          ];
          this.search();
        }
      }
    },

    // 赠送云币
    giveCoin(curInfo) {
      this.curMemberId = curInfo.memberId;
      this.showGiveCoinDialog = true;
    },

    // 云币明细
    relatedCoin(curInfo) {
      this.$router.push({
        name: 'cloudCoinDetail',
        params: {
          memberId: curInfo.memberId,
          type: 0
        }
      })
    },

    // 关联的订单查询
    relatedOrder(curInfo) {
      if(!curInfo.cellPhoneNo){
        this.$message.error('该用户未设置手机号');
      }
      // return
      this.$router.push({
        name: 'normalOrderSearch',
        params: {
          cellPhoneNo: curInfo.cellPhoneNo
        }
      })
    }
  },
};
</script>
<style lang="less" scoped>
.toptitle {
  border: 1px solid #e0e0e0;
  border-bottom: 2px solid #188097;
  background: #f5f5f5;
  line-height: 35px;
  margin-bottom: 10px;
  padding: 0 10px;
  font-size: 14px;
  font-weight: bold;
}

.limttable {
  width: 500px;
  float: left;
}

.limttree {
  display: inline-block;

  border-top: 48px solid rgb(238, 241, 246);
  width: 206px;
  margin-left: 150px;
}

.demo-form-inline {
  //   border: 1px solid #ebeef5;
  padding: 20px 10px 3px 30px;
  margin-bottom: 25px;
}

.toptitle {
  border: 1px solid #e0e0e0;
  border-bottom: 2px solid #188097;
  background: #f5f5f5;
  line-height: 35px;
  margin-bottom: 10px;
  padding: 0 10px;
  font-size: 14px;
  font-weight: bold;
}

.limttreecontain {
  height: 260px;
  width: 200px;
  overflow: scroll;
  border: 1px solid #ccc;
}

.order_content {
  width: 200px;
  padding: 20px 0;
  margin: 0 auto;
  text-align: center;
  overflow: hidden;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
}

.order_content .order_total_title {
  color: #000;
}

.order_content .order_total_info {
  margin: 10px 0;
}

.order_content .order_data {
  font-size: 1.4em;
  font-weight: bold;
}

.order_content .compared_title {
  font-size: 0.8em;
  color: #999;
}

.demo-form-inline .el-form-item {
  margin-bottom: 0px;
}

.el-row {
  margin-bottom: 0px !important;
}
</style>
<style lang="scss" scoped>
.table-wrapper {
  /deep/ .el-table__fixed-right .el-table__fixed-body-wrapper {
    height: 329px !important;
  }
}
</style>
